package com.mediatek.factorymode.touchscreen1;

import android.app.Activity;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.res.Configuration;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.util.Log;
import android.view.KeyEvent;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;

import com.mediatek.factorymode.AppDefine;
import com.mediatek.factorymode.R;
import com.mediatek.factorymode.Utils;

/*
public static final int VISIBLE = 0x00000000;
public static final int INVISIBLE = 0x00000004;
public static final int GONE = 0x00000008;
*/

public class TouchScreenTest extends Activity {
    private int i = 0;
    View mCircleView;
    private SharedPreferences mSp;
    BroadcastReceiver mReceiver = new BroadcastReceiver()
    {
        public void onReceive(Context paramAnonymousContext, Intent paramAnonymousIntent)
        {
            int result =  paramAnonymousIntent.getIntExtra("TestPass", 0);
            android.util.Log.d("tanglei", "result = " + result);
            if (result == 2){
                TouchScreenTest.this.i+= 1;
                Intent intent = new Intent();
                intent.setClass(TouchScreenTest.this, DrawLineView.class);
                TouchScreenTest.this.startActivity(intent);
                return;
            } else if (result == 3){
                TouchScreenTest.this.mCircleView.setVisibility(View.GONE);
                TouchScreenTest.this.mRectangleView.setVisibility(View.GONE);
                Utils.SetPreferences(getApplicationContext(), mSp, R.string.touchscreen_name,
                        "success");
                finish();

            }
        }
    };
    View mRectangleView;

    public void onClick(View paramView) {}

    public void onConfigurationChanged(Configuration paramConfiguration)
    {
        super.onConfigurationChanged(paramConfiguration);
    }

    public void onCreate(Bundle paramBundle)
    {
        super.onCreate(paramBundle);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                    WindowManager.LayoutParams.FLAG_FULLSCREEN);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        View decorView = getWindow().getDecorView();
        decorView.setSystemUiVisibility(
                View.SYSTEM_UI_FLAG_LAYOUT_STABLE
                | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
                | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
                | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
                | View.SYSTEM_UI_FLAG_FULLSCREEN
                | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY);


        setContentView(R.layout.tp_test);
        this.mCircleView = findViewById(R.id.circleView);
        this.mRectangleView = findViewById(R.id.rectangleView);
        registerReceiver(this.mReceiver, new IntentFilter("com.mediatek.factorymode.touchscreen.test.action.finish"));
        mSp = getSharedPreferences("FactoryMode", Context.MODE_PRIVATE);
        TouchScreenTest.this.mCircleView.setVisibility(View.GONE);
        TouchScreenTest.this.mRectangleView.setVisibility(View.VISIBLE);
    }

    @Override
    public void onWindowFocusChanged(boolean hasFocus) {
        super.onWindowFocusChanged(hasFocus);
        if (hasFocus) {
            View decorView = getWindow().getDecorView();
            decorView.setSystemUiVisibility(
                    View.SYSTEM_UI_FLAG_LAYOUT_STABLE
                    | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
                    | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
                    | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
                    | View.SYSTEM_UI_FLAG_FULLSCREEN
                    | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY);
        }
    }

    protected void onDestroy()
    {
        super.onDestroy();
        unregisterReceiver(this.mReceiver);
    }

    public boolean onKeyDown(int paramInt, KeyEvent paramKeyEvent)
    {
        if (paramInt == 4) {}
        while ((paramInt == 82) || (paramInt == 3)) {
            return true;
        }
        return super.onKeyDown(paramInt, paramKeyEvent);
    }
}
